/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.support.ohos.designlibdemo.pref;

import ohos.agp.utils.Point;
import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

/**
 * Display显示模式操作
 */
public final class DisplayMode {
    /**
     * 日间模式
     */
    public static final int MODEL_DAY = 1;

    /**
     * 夜间模式
     */
    public static final int MODEL_NIGHT = 2;

    private static int DISPLAY_MODE = -1;

    /**
     * 是否存在夜间模式
     *
     * @return 模式
     */
    public static boolean hasDisplayMode() {
        return DISPLAY_MODE != -1;
    }

    /**
     * 获取当前显示模式(日间or夜间,默认日间)
     *
     * @return 模式result
     */
    public static int getDisplayMode() {
        int mode = DISPLAY_MODE;
        if (mode != MODEL_DAY && mode != MODEL_NIGHT) {
            mode = MODEL_DAY;
        }
        return mode;
    }

    /**
     * 设置当前的显示模式
     *
     * @param value 模式(日间or夜间)
     */
    public static void setDisplayMode(int value) {
        DISPLAY_MODE = value;
    }

    /**
     * 是否是夜间模式
     *
     * @return result(boolean)
     */
    public static boolean isNight() {
        int mode = getDisplayMode();
        boolean night = false;
        if (mode == MODEL_NIGHT) {
            night = true;
        }
        return night;
    }

    /**
     * 获取屏幕高度(整个屏幕的)
     *
     * @param context 上下文
     * @return 高度height
     */
    public static int getScreenHeight(Context context) {
        Point point = new Point();
        DisplayManager.getInstance().getDefaultDisplay(context).get().getRealSize(point);
        return point.getPointYToInt();
    }

    /**
     * 获取显示高度(去除状态栏和导航栏，也就是页面内容的高度)
     *
     * @param context 上下文
     * @return 高度height
     */
    public static int getDisplayHeight(Context context) {
        Point point = new Point();
        DisplayManager.getInstance().getDefaultDisplay(context).get().getSize(point);
        return point.getPointYToInt();
    }
}